package com.eschool.beans;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import com.eschool.beans.converter.ClassConverter;
import com.eschool.model.Clas;
import com.eschool.model.Section;
import com.eschool.service.SchoolManagementService;
import com.eschool.service.impl.SchoolManagementServiceImpl;

@ManagedBean(name="sectionBean")
@ViewScoped
public class SectionBean {
	
	private Section section = new Section();	
	private List<Clas> classes;
	
	SchoolManagementService service = new SchoolManagementServiceImpl();

	public SectionBean() {
		classes = new ArrayList<Clas>();
		classes = ClassConverter.classDB;
	}
	public List<Clas> getClasses() {
		return classes;
	}
	public void setClasses(List<Clas> classes) {
		this.classes = classes;
	}
	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}

	public String performAction()
	{
		String message;
		
		//clas.setSession(SessionDao.getSessionByProperty("sessionId", 1));

		if(service.addSection(section)) {
			message = "Section Successfully Added";
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Info message", message));
		}
		else {
			message = "Section Not Added";
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error Message", message));
		}		
		
		return "AddSection";
	}



}
